<%--
  Created by IntelliJ IDEA.
  User: 86180
  Date: 2021/2/2
  Time: 14:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>

<html class="app-ui">

<head>
    <!-- Meta -->
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />

    <!-- Document title -->
    <title>Home</title>

    <meta name="description" content="AppUI - Frontend Template & UI Framework" />
    <meta name="robots" content="noindex, nofollow" />

    <!-- Favicons -->
    <link rel="apple-touch-icon" href="${pageContext.request.contextPath}/assets/img/favicons/apple-touch-icon.png" />
    <link rel="icon" href="${pageContext.request.contextPath}/assets/img/favicons/favicon.ico" />

    <!-- AppUI CSS stylesheets -->
    <link rel="stylesheet" id="css-font-awesome" href="${pageContext.request.contextPath}/assets/css/font-awesome.css" />
    <link rel="stylesheet" id="css-ionicons" href="${pageContext.request.contextPath}/assets/css/ionicons.css" />
    <link rel="stylesheet" id="css-bootstrap" href="${pageContext.request.contextPath}/assets/css/bootstrap.css" />
    <link rel="stylesheet" id="css-app" href="${pageContext.request.contextPath}/assets/css/app.css" />
    <link rel="stylesheet" id="css-app-custom" href="${pageContext.request.contextPath}/assets/css/app-custom.css" />
    <!-- AppUI Core JS: jQuery, Bootstrap, slimScroll, scrollLock and App.js -->
    <script src="${pageContext.request.contextPath}/assets/js/core/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/assets/js/core/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/assets/js/core/jquery.slimscroll.min.js"></script>
    <script src="${pageContext.request.contextPath}/assets/js/core/jquery.scrollLock.min.js"></script>
    <script src="${pageContext.request.contextPath}/assets/js/core/jquery.placeholder.min.js"></script>
    <script src="${pageContext.request.contextPath}/assets/js/app.js"></script>
    <script src="${pageContext.request.contextPath}/assets/js/app-custom.js"></script>

    <!-- End Stylesheets -->
    <script type="text/javascript">
        $(function (){
            /*动态显示首页头部*/
            var role = ${account.role};
            if(role == 2){
                $("#business").html("<a href='../business/UnFinishOrder.jsp'>商家后台</a>");
                $("#deliver").html("");
            }
            if(role == 3){
                $("#business").html("");
                $("#deliver").html("<a href='#'>配送员后台</a>");
            }


            var accId = ${account.accId};
            var pageCurrent = 1;
            var pageSize = 8;
            var goNm = null;
            var goodsCount=0;//数据笔数
            var allGoodsPage = 0;//总页数
            getGoodsList();
            /*  获取商品信息--start    */
            function getGoodsList() {
                var url = "${pageContext.request.contextPath}/goods/selectGoodsListByGoNmOrSelectAll";
                var param = {
                    accId:accId,
                    goNm:goNm,
                    pageCurrent:pageCurrent,
                    pageSize:pageSize
                };
                $.get(url,param,function (data) {
                    if (data.code == 1001){
                        var ux = "";
                        $("#pageCurrent").html(pageCurrent);
                        $("#goodsContent").html("");
                        var content = "<div class='row'>";
                        for (var i = 0; i < data.goodsList.length;i++){
                            if (i == 4){
                                content += "</div>";
                                content += "<div class='row'>";
                            }
                        content += "<div class='col-sm-6 col-lg-3'>";
                        content += "<div class='card'>";
                        content += "<a href='${pageContext.request.contextPath}/jsp/goods/frontend_about.jsp?xxwhatId="+eval(data.goodsList[i].goId*1024)+"'>";
                        content += "<div class='card-block bg-img' style='background-image: url(${pageContext.request.contextPath}/file/goodsInfo/"+data.goodsList[i].imgUrl+");height: 200px;'></div>";
                        content += "<div class='card-block'>";
                        content += "<span>"+data.goodsList[i].goods.goNm+"</span>";
                        content += "<code style='margin-left: 30px;'>月售"+data.goodsList[i].sellNum+"</code>"
                        content += "<div class='card-actions'>￥<span>"+data.goodsList[i].goods.goPri+"</span></div>";
                        content += "</div>";
                        content += "</a>"
                        content += "</div>";
                        content += "</div>";
                        }
                        content += "</div>";
                        $("#goodsContent").html(content);
                        goodsCount = data.goodsCount;
                        /*设置数据总笔数*/
                        allGoodsPage = parseInt(goodsCount/pageSize)+1;
                        $("#allGoodsPage").html(allGoodsPage);
                    }else {
                        alert("查询失败");
                    }
                });
            }
            /*  获取商品信息--end    */

            /* 分页按钮--start */
            $("#right").click(function () {
                if (allGoodsPage < pageCurrent+1){
                    return false;
                }
                pageCurrent += 1;
                $("#pageCurrent").html(pageCurrent)
                getGoodsList();
            })
            $("#left").click(function () {
                if (pageCurrent-1 < 1){
                    return false;
                }
                pageCurrent -= 1;
                $("#pageCurrent").html(pageCurrent)
                getGoodsList();

            })
            $("#first").click(function () {
                if (pageCurrent == 1){
                    return false;
                }
                pageCurrent = 1;
                $("#pageCurrent").html(pageCurrent)
                getGoodsList();
            });
            $("#last").click(function () {
                if (pageCurrent == allGoodsPage){
                    return false;
                }
                pageCurrent = allGoodsPage;
                $("#pageCurrent").html(pageCurrent)
                getGoodsList();
            });
            /* 分页按钮--end */
            /*  搜索商品--start    */
            $("#searchGoods").click(function () {
                goNm = $("#search-input").val();
                getGoodsList();
            });
            /*  搜索商品--end    */

            /*退出登录*/
            $("#logout").click(function (event){
                event.preventDefault();
                var url = "/login/logoutShop";
                $.post(url,function (){
                    window.location.href = "../../login.jsp";
                })
            })


        });

    </script>
</head>

<body class="app-ui">
<div class="app-layout-canvas">
    <div class="app-layout-container">

        <!-- Header -->
        <header class="app-layout-header">
            <nav class="navbar navbar-default p-y">
                <div class="container">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#header-navbar-collapse"
                                aria-expanded="false">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <!-- Header logo -->
                        <a class="navbar-brand" href="javascript:void(0)">
                            <img class="img-responsive" src="${pageContext.request.contextPath}/assets/img/logo/logo-frontend.png" title="强强组合商城" alt="AppUI" />
                        </a>
                    </div>

                    <div class="collapse navbar-collapse" id="header-navbar-collapse">
                        <!-- Header search form -->

                        <!-- Header navigation menu -->
                        <ul id="main-menu" class="nav navbar-nav navbar-left">

                            <li class="active">
                                <a href="frontend_home.html">首页</a>
                            </li>

                            <li>
                                <a href="frontend_about.html">关于</a>
                            </li>

                            <li>
                                <a href="frontend_pricing.html">Pricing</a>
                            </li>

                            <li>
                                <a href="frontend_team.html">Team</a>
                            </li>

                            <li class="dropdown">
                                <a href="#" data-toggle="dropdown">分类 <span class="caret"></span></a>
                                <ul class="dropdown-menu">

                                    <li>
                                        <a href="frontend_search.html">Search</a>
                                    </li>

                                    <li>
                                        <a href="frontend_support.html">Support</a>
                                    </li>

                                    <li>
                                        <a href="frontend_contact.html">Contact</a>
                                    </li>

                                    <li>
                                        <a href="frontend_login_signup.html">Login / Signup</a>
                                    </li>

                                    <li>
                                        <a href="frontend_400.html">Error 400</a>
                                    </li>

                                </ul>
                            </li>

                        </ul>
                        <!-- End header navigation menu -->

                        <ul class="nav navbar-nav navbar-right navbar-toolbar hidden-sm hidden-xs">
                            <li class="active" id="business">
                                <a href="#" id="registerBusiness">注册为商家</a>
                            </li>
                            <li class="active" id="deliver">
                                <a href="frontend_home.html">注册为配送员</a>
                            </li>
                            <li class="dropdown">
                                <a href="javascript:void(0)" data-toggle="dropdown"><i class="ion-ios-bell"></i> <span class="badge">3</span></a>
                                <ul class="dropdown-menu dropdown-menu-right">
                                    <li class="dropdown-header">Profile</li>
                                    <li>
                                        <a tabindex="-1" href="javascript:void(0)"><span class="badge pull-right">3</span> News </a>
                                    </li>
                                    <li>
                                        <a tabindex="-1" href="javascript:void(0)"><span class="badge pull-right">1</span> Messages </a>
                                    </li>
                                    <li class="divider"></li>
                                    <li class="dropdown-header">More</li>
                                    <li>
                                        <a tabindex="-1" href="javascript:void(0)">Edit Profile..</a>
                                    </li>
                                </ul>
                            </li>

                            <li class="dropdown dropdown-profile">
                                <a href="javascript:void(0)" data-toggle="dropdown">
                                    <span class="m-r-sm">${account.accName}<span class="caret"></span></span>
                                    <img class="img-avatar img-avatar-48" src="${pageContext.request.contextPath}/file/acc/${account.accImg == null?"000000011612245316757212.png":account.accImg}" alt="User profile pic" />
                                </a>
                                <ul class="dropdown-menu dropdown-menu-right">
                                    <li>
                                        <a href="${pageContext.request.contextPath}/jsp/MyAccount/MyMoneyRecord.jsp">个人账户</a>
                                    </li>
                                    <li>
                                        <a href="${pageContext.request.contextPath}/jsp/MyAccount/myBuyCart.jsp">我的购物车</a>
                                    </li>
                                    <li>
                                        <a href="#" id="logout">退出</a>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                </div>
                <!-- .container -->
            </nav>
            <!-- .navbar -->
        </header>
        <!-- End header -->

        <main class="app-layout-content">
            <div class="container col-md-12">
                <div class="row vcenter-md">
                    <div class="row m-b-md">
                        <div class="col-md-12 col-md-offset-6 text-center">
                            <form class="navbar-form navbar-right app-search-form" role="search">
                                <div class="form-group">
                                    <div class="input-group input-group-lg">
                                        <input class="form-control" style="width: 600px;border-color: red;border-right: green" type="search" id="search-input" placeholder="搜索..." />
                                        <span class="input-group-btn">
													<button class="btn btn-success" style="width: 100px;border-color: red;border-left: green;" type="button" id="searchGoods"><i class="ion-ios-search-strong"></i></button>
												</span>
                                    </div>
                                </div>
                            </form>

                        </div>
                    </div>
                </div>
                <!-- .row -->
            </div>

            <div class="section">
                <div class="container p-y-xl b-b">

                    <!-- .row -->
                    <div id="goodsContent">

                    </div>
                    <!-- .row -->
                    <div class="text-center">
                        <button class="btn btn-info" type="button" data-toggle="tooltip" title="首页" id="first"><i class="fa fa-angle-double-left"></i></button>&nbsp;&nbsp;&nbsp;
                        <button class="btn btn-info" type="button" data-toggle="tooltip" title="上一页" id="left"><i class="fa fa-angle-left"></i></button>&nbsp;&nbsp;&nbsp;
                        <button class="btn btn-info" type="button" data-toggle="tooltip" title="下一页" id="right"><i class="fa fa-angle-right"></i></button>&nbsp;&nbsp;&nbsp;
                        <button class="btn btn-info" type="button" data-toggle="tooltip" title="尾页" id="last"><i class="fa fa-angle-double-right"></i></button>&nbsp;&nbsp;&nbsp;
                        总页数:<span id="allGoodsPage"></span>&nbsp;&nbsp;当前为第<span id="pageCurrent"></span>页
                    </div>
                </div>
                <!-- .container -->
            </div>

            <!-- .section -->

            <div class="section p-y-xl bg-app bg-inverse">
                <div class="container text-center">
                    <!-- .row -->
                    <div class="row p-t-md p-b-lg">
                        <div class="col-md-10 col-md-offset-1">
                        </div>
                    </div>
                    <!-- .row -->
                </div>
                <!-- .container -->
            </div>
            <!-- .section -->

        </main>
    </div>
    <!-- .app-layout-container -->
</div>
<!-- .app-layout-canvas -->

</body>
<script src="${pageContext.request.contextPath}/js/layui/layui.js"></script>

<script>
    $(function (){
        var accId = ${account.accId};
        var businessSign = "";
        //获取商家申请状态
        var param = {
            accId:accId
        }
        var url = "/accountInfo/selectAccountByAccId";
        $.get(url,param,function (data){
            if(data.code == 1001){
                businessSign = data.account.businessSign;
            }
        })

        layui.use(['form', 'layedit', 'laydate'], function() {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;

            $("#registerBusiness").click(function (event) {
                event.preventDefault();
                if(businessSign == 1){
                    layer.msg("您已申请过，请等待管理员审核");
                }else {
                    layer.open({
                        type: 2,  //设置弹窗类型为 2，表示弹出一个页面
                        title: '商家注册', //弹窗标题
                        skin: 'layui-layer-rim', //加上边框
                        area: ['600px', '350px'], //设置弹窗的宽高
                        content: '../account/registerBusiness.jsp?accId=' + accId   //以弹出层的形式跳转到 商家注册页面，并附带参数
                    });
                }

            })

        })


    })
</script>

</html>
